package com.keur.money.utils.dialog

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.keur.money.R
import com.keur.money.base.utils.ImageUtil
import com.keur.money.databinding.DialogMullaLuckyDrawAnimBinding
import com.keur.money.http.HttpHelper
import com.keur.money.utils.event.KeurEventType

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/7/8 15:50
 * @Annotation：抽奖动画提示dialog
 */
class LuckyDrawAnimDialog: ProDialog {

    private lateinit var binding: DialogMullaLuckyDrawAnimBinding
    private var mCallback: IDialogCallback? = null

    override fun initWindow() {
        val params = window?.attributes
        params?.width = WindowManager.LayoutParams.MATCH_PARENT
        params?.height = WindowManager.LayoutParams.WRAP_CONTENT
        window?.attributes = params
        window?.setWindowAnimations(R.style.dialog_scale_anim) //修改动画样式
        window?.setGravity(Gravity.CENTER)
    }

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogMullaLuckyDrawAnimBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
        ImageUtil.instance?.loadImageRes(context,binding.imgAnim,R.mipmap.mulla_user_lucky_draw_anim)
    }

    override fun initListener() {
    }

    override fun initData() {
        Handler(Looper.getMainLooper()).postDelayed({
            if (mCallback != null){
                mCallback?.showComplete()
            }
            dismiss()
        },2500)
    }

    override fun onViewClick(v: View?) {
    }

    interface IDialogCallback {
        fun showComplete()
    }

    override fun onStart() {
        super.onStart()
        HttpHelper.addKeurEventAction(KeurEventType.DIALOG.KEUR_DIALOG_LUCKY_DRAW_ANIM_SHOW)
    }

    override fun dismiss() {
        super.dismiss()
        HttpHelper.addKeurEventAction(KeurEventType.DIALOG.KEUR_DIALOG_LUCKY_DRAW_ANIM_DISMISS)
    }
}